package com.sigmatrix.h5.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.sigmatrix.h5.dao.MultistageLevelQrCodeDao;
import com.sigmatrix.h5.dto.ProductData;
import com.sigmatrix.h5.dto.QRCodeError;
import com.sigmatrix.h5.entity.FirstLevelQRCode;
import com.sigmatrix.h5.entity.MultistageLevelQRCode;
import com.sigmatrix.h5.enums.MultistageLevelQRCodeStatusEnum;
import com.sigmatrix.h5.enums.PackScanOperTypeEnum;
import com.sigmatrix.h5.enums.VisualCodeType;
import com.sigmatrix.h5.exception.DaoException;
import com.sigmatrix.h5.exception.ServiceException;
import com.sigmatrix.h5.service.FirstLevelQrCodeService;
import com.sigmatrix.h5.service.MultistageLevelQrCodeService;
import com.sigmatrix.h5.service.ProductService;
import com.sigmatrix.h5.service.WarehouseStockDetailsService;
import com.sigmatrix.h5.utils.Cons;
import com.sigmatrix.h5.utils.QRCodeUtil;
import com.sigmatrix.h5.utils.SessionUtils;
import com.sigmatrix.h5.utils.Utils;
import com.sigmatrix.h5.web.vo.InStorageVo;
import com.sigmatrix.h5.web.vo.OperateCodeVo;
import com.sigmatrix.h5.web.vo.OutStorageVo;
import com.sigmatrix.sc.mongo.common.service.MongoServiceImpl;
/**
 * 
 *@ClassName: MultistageLevelQrCodeServiceImpl
 *@Description: 多级码表
 *@author MH
 *@date 2017年9月22日 上午9:53:47
 */
@Service
public class MultistageLevelQrCodeServiceImpl extends MongoServiceImpl<MultistageLevelQRCode> implements MultistageLevelQrCodeService{

	/**logger record*/
	private static final Logger LOGGER = LoggerFactory.getLogger(MultistageLevelQrCodeServiceImpl.class);
	
	/**注入mongoTemplate*/
	@Autowired
	private transient MongoTemplate mongoTemplate;

	/**多级码mongo操作接口*/
	@Autowired
	private transient MultistageLevelQrCodeDao multistageLevelQRCodeDao;
	
	/**一级码业务层操作接口*/
	@Autowired
	private transient FirstLevelQrCodeService firstLevelQRCodeService;
	
	/**产品业务层接口*/
	@Autowired
	private transient ProductService productService;
	
	/**库存明细业务接口 */
	@Autowired
	private transient WarehouseStockDetailsService warehouseStockDetailsService;
	
	/**多级码已经出库的状态集合*/
	private static List<Integer> alreadyOutStorageStatusList = new ArrayList<Integer>();
	
	/**多级码已经入库的状态集合*/
	private static List<Integer> alreadyInStorageStatusList = new ArrayList<Integer>();
	
	static {
		alreadyOutStorageStatusList.add(MultistageLevelQRCodeStatusEnum.SALES_OUT_STORAGE.getId());
		alreadyOutStorageStatusList.add(MultistageLevelQRCodeStatusEnum.REWORK_OUT_STORAGE.getId());
		alreadyOutStorageStatusList.add(MultistageLevelQRCodeStatusEnum.TRANSFERS_OUT_STORAGE.getId());
		alreadyOutStorageStatusList.add(MultistageLevelQRCodeStatusEnum.OTHER_OUT_STORAGE.getId());
		
		alreadyInStorageStatusList.add(MultistageLevelQRCodeStatusEnum.IN_STORAGE.getId());
	}
	
	
	@Override
	public MultistageLevelQRCode findBySeqNum(String seqNum) {
		MultistageLevelQRCode vo = new MultistageLevelQRCode();
		vo.setSeqNum(seqNum);
		vo.setEnterpriseCode(SessionUtils.getEseCode());
		return selectOne(vo);
	}
	
	@Override
	public MultistageLevelQRCode findBySeqNum(String seqNum,String eseCode) {
		MultistageLevelQRCode vo = new MultistageLevelQRCode();
		vo.setSeqNum(seqNum);
		vo.setEnterpriseCode(eseCode);
		return selectOne(vo);
	}

	@Override
	public MultistageLevelQRCode findByFriendlyCode(String friendlyCode) {
		MultistageLevelQRCode vo = new MultistageLevelQRCode();
		vo.setFriendlyCode(friendlyCode);
		vo.setEnterpriseCode(SessionUtils.getEseCode());
		return selectOne(vo);
	}

	@Override
	public MultistageLevelQRCode findByPackContent(String packContent) {
		MultistageLevelQRCode vo = new MultistageLevelQRCode();
		vo.setPackContent(packContent);
		vo.setEnterpriseCode(SessionUtils.getEseCode());
		return selectOne(vo);
	}
	
	@Override
	public MultistageLevelQRCode findByPackContent(String packContent,String eseCode) {
		MultistageLevelQRCode vo = new MultistageLevelQRCode();
		vo.setPackContent(packContent);
		vo.setEnterpriseCode(eseCode);
		return selectOne(vo);
	}

	@Override
	public MultistageLevelQRCode findBySeqOrFriendlyCode(String code, Short codeType) {
		if(VisualCodeType.SEQ_NUM.value.equals(codeType)){
			return findBySeqNum(code);
		}else{
			return findByFriendlyCode(code);
		}
	}

	@Override
	public List<MultistageLevelQRCode> findByParent(String parentCode) {
		MultistageLevelQRCode vo = new MultistageLevelQRCode();
		vo.setEnterpriseCode(SessionUtils.getEseCode());
		vo.setParentCode(parentCode);
		return select(vo);
	}

	@Override
	public MultistageLevelQRCode findByParallelCode(String qrCode) {
		MultistageLevelQRCode vo = new MultistageLevelQRCode();
		vo.setParallelCode(qrCode);
		vo.setEnterpriseCode(SessionUtils.getEseCode());
		return selectOne(vo);
	}
	
	/**
	 * (non-Javadoc)
	 *@Title: findMultistageLevelQRCodeByQRCodeAndLevel
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#findMultistageLevelQRCodeByQRCodeAndLevel(java.lang.String, java.lang.String, java.lang.Integer, boolean)
	 *@author youjun
	 *@date 2017年8月8日 下午4:30:24
	 */
	@Override
	public MultistageLevelQRCode findMultistageLevelQRCodeByQRCodeAndLevel(final String enterpriseCode, final String qRCode, 
			final Integer qRCodeLevel, final Integer codeType, final boolean isNeedConversion) throws ServiceException {
		
		if(StringUtils.isBlank(enterpriseCode)
				||StringUtils.isBlank(qRCode)) {
			throw new ServiceException("参数有误");
		}
		try {
			int newCodeType = 1;
			if(codeType!=null) {
				newCodeType = codeType;
			}
			final String code = QRCodeUtil.conversionQRCode(qRCode, isNeedConversion);
			if(newCodeType==Cons.CODE_TYPE_STANDARD || newCodeType==Cons.CODE_TYPE_CIPHER) {
				return multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCodeAndLevel(enterpriseCode, code, qRCodeLevel);
			}else if(newCodeType==Cons.CODE_TYPE_FRIENDLY){
				return multistageLevelQRCodeDao.findMultistageLevelQRCodeBySeqNumAndLevel(enterpriseCode, code, qRCodeLevel);
			}else if(newCodeType==Cons.CODE_TYPE_SEQNUM) {
				return multistageLevelQRCodeDao.findMultistageLevelQRCodeByFriendlyCodeAndLevel(enterpriseCode, code, qRCodeLevel);
			}
			return multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, code);
		} catch (DaoException e) {
			throw new ServiceException(e);
		}
	}
	
	/**(non-Javadoc)
	 *@Title: findMultistageLevelQRCodeByQRCode
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#findMultistageLevelQRCodeByQRCode(java.lang.String, java.lang.String)
	 *@author youjun
	 *@date 2017年8月7日 下午1:54:58
	 */
	@Override
	public MultistageLevelQRCode findMultistageLevelQRCodeByQRCode(final String enterpriseCode, final String qRCode, final Integer codeType, final boolean isNeedConversion)
			throws ServiceException {
		
		try {
			int newCodeType = Cons.CODE_TYPE_STANDARD;
			if(codeType!=null) {
				newCodeType = codeType;
			}
			final String code = QRCodeUtil.conversionQRCode(qRCode, isNeedConversion);
			if(newCodeType==Cons.CODE_TYPE_STANDARD || newCodeType==Cons.CODE_TYPE_CIPHER) {
				return multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, code);
			}else if(newCodeType==Cons.CODE_TYPE_FRIENDLY){
				return multistageLevelQRCodeDao.findMultistageLevelQRCodeByFriendlyCode(enterpriseCode, code);
			}else if(newCodeType==Cons.CODE_TYPE_SEQNUM) {
				return multistageLevelQRCodeDao.findMultistageLevelQRCodeBySeqNum(enterpriseCode, code);
			}
			return multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, code);
		} catch (DaoException e) {
			throw new ServiceException(e);
		}
	}
	
	/**
	 * (non-Javadoc)
	 *@Title: getInventedCodeRelatedInfo
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#getInventedCodeRelatedInfo(java.lang.String, java.lang.String, java.lang.Integer, boolean, int, boolean)
	 *@author youjun
	 *@date 2017年8月11日 下午8:33:01
	 */
	@Override
	public Map<String, Object> getInventedCodeRelatedInfo(final String enterpriseCode,  
			final String qRCode, final Integer codeLevel, final boolean isNeedConversion, final int packLevel, 
			final boolean isSelectChildPackLevelCode) throws ServiceException {
		
		LOGGER.info("查询虚拟码(码级别大于包装级别的码)及虚拟码的相关信息开始...");
		if(StringUtils.isBlank(enterpriseCode)
				|| StringUtils.isBlank(qRCode)) {
			throw new ServiceException("企业code或查询的码不能为空");
		}
		final Map<String, Object> map = new HashMap<String, Object>();
		final String code = QRCodeUtil.conversionQRCode(qRCode, isNeedConversion);
		try{
			final MultistageLevelQRCode multisCode = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCodeAndLevel(enterpriseCode, code, codeLevel);
			if(multisCode!=null) {
				LOGGER.info("查询到的多级码为:{}", JSONObject.toJSONString(multisCode));
				// 获得虚拟码下的所有包装码
				final List<String> packCodeList = recursionPackCodeList(enterpriseCode, multisCode, packLevel);
				map.put("packCodeList", packCodeList);
				int packCodeCount = 0;
				if(CollectionUtils.isNotEmpty(packCodeList)){
					packCodeCount = packCodeList.size();
					if(isSelectChildPackLevelCode) { // 查询子码信息,放入list中
						final List<MultistageLevelQRCode> packMultistageLevelList = new ArrayList<MultistageLevelQRCode>();
						final List<FirstLevelQRCode> packFirstLevelList = new ArrayList<FirstLevelQRCode>();
						if(multisCode.getPackLevel()>1){ // 子码为包装码    包装码包装级别大于1
							for(final String childCode:packCodeList) {
								final MultistageLevelQRCode multiCode = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, childCode);
								packMultistageLevelList.add(multiCode);
							}
						}else{ // 子码为单品码    单品码包装级别是1
							for(final String childCode:packCodeList) {
								final FirstLevelQRCode firstQRCode = firstLevelQRCodeService.findFirstLevelQRCodeByQRCode(enterpriseCode, childCode, false);
								packFirstLevelList.add(firstQRCode);
							}
						}
						map.put("packMultistageLevelList", packMultistageLevelList);
						map.put("packFirstLevelList", packFirstLevelList);
					}
					LOGGER.info("查询到的多级码下的所有包装码为:{}", JSONObject.toJSONString(packCodeList));
				}
				LOGGER.info("查询到的多级码下的所有包装码数量为:{}", packCodeCount);
				map.put("packCodeCount", packCodeCount);
			}else{
				LOGGER.info("多级码不存在");
			}
			map.put("multistageLevelQRCode", multisCode);
			LOGGER.info("查询虚拟码(码级别大于包装级别的码)及虚拟码的相关信息结束...");
		}catch(Exception e){
			LOGGER.error("查询虚拟码(码级别大于包装级别的码)及相关信息失败", e);
			throw new ServiceException(e);
		}
		return map;
	}
	
	/**
	 * (non-Javadoc)
	 *@Title: recursionPackCodeList
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#recursionPackCodeList(java.lang.String, com.sigmatrix.sc.handheld.inter.entity.MultistageLevelQRCode, int)
	 *@author youjun
	 *@date 2017年8月6日 下午5:01:03
	 */
	@Override
	public List<String> recursionPackCodeList(final String enterpriseCode, 
			final MultistageLevelQRCode code, final int productPackLevel) throws ServiceException {

		if(StringUtils.isBlank(enterpriseCode)
				||code==null
				||code.getPackLevel()==null) {
			throw new ServiceException("企业code或多级码信息不正确");
		}
		try{
			if(code.getPackLevel()<=productPackLevel){
				return null;
			}
			List<String> totalPackCodeList = new ArrayList<String>();
			if(code.getPackLevel()==productPackLevel+1) { // 当前码的包装级别比产品的包装单位大1说明下级码是包装单位级别
				final String[] codeArray = StringUtils.isNotBlank(code.getChilds())?code.getChilds().split(Cons.CHILD_CODE_SEPARATOR):new String[]{};
				CollectionUtils.addAll(totalPackCodeList, codeArray);
				return totalPackCodeList;
			}
			final String childQRCodes = code.getChilds();
			if(StringUtils.isNotBlank(childQRCodes)) {
				final String[] childQRCodeArray = childQRCodes.split(Cons.CHILD_CODE_SEPARATOR);
				MultistageLevelQRCode item = null;
				for(final String childCode:childQRCodeArray) {
					item = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, childCode);
					totalPackCodeList=getPackLevelPackCodeList(totalPackCodeList, enterpriseCode, item, productPackLevel);
				}
			}
			
			return totalPackCodeList;
		}catch(Exception e){
			throw new ServiceException(e);
		}
		
	}
	
	/**
	 *@Title: getPackLevelPackCodeList
	 *@Description: 获得多级码的包装码集合
	 *@return List<String>
	 *@author youjun
	 *@date 2017年8月6日 下午4:59:35
	 *@param packCodeList
	 *@param enterpriseCode
	 *@param code
	 *@param productPackLevel
	 *@return
	 *@throws ServiceException
	 */
	private List<String> getPackLevelPackCodeList(final List<String> packCodeList, final String enterpriseCode, 
			final MultistageLevelQRCode code, final int productPackLevel) throws ServiceException {
		
		try{
			final List<String> totalPackCodeList = packCodeList;
			if(code.getPackLevel()==productPackLevel+1) { // 当前码的包装级别比产品的包装单位大1说明下级码数量是包装单位级别的数量
				LOGGER.info("当前为包装单位级别{}的码,有{}个包装单位级别码", productPackLevel, code.getChildNum());
				if(StringUtils.isNotBlank(code.getChilds())){
					String[] childs = code.getChilds().split(Cons.CHILD_CODE_SEPARATOR);
					CollectionUtils.addAll(totalPackCodeList, childs);
				}
			}else{
				final String childQRCodes = code.getChilds();
				if(StringUtils.isNotBlank(childQRCodes)) {
					final String[] childQRCodeArray = childQRCodes.split(Cons.CHILD_CODE_SEPARATOR);
					MultistageLevelQRCode item = null;
					for(final String childCode:childQRCodeArray) {
						item = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, childCode);
						return getPackLevelPackCodeList(totalPackCodeList, enterpriseCode, item, productPackLevel);
					}
				}
			}
			return totalPackCodeList;
		}catch(Exception e){
			throw new ServiceException(e);
		}
		
	}

	/**(non-Javadoc)
	 *@Title: updateOutStorageCode
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#updateOutStorageCode(com.sigmatrix.sc.handheld.inter.web.vo.OutStorageVo, java.util.Map)
	 *@author youjun
	 *@date 2017年8月14日 上午10:18:37
	 */
	@Override
	public void updateOutStorageCode(final OutStorageVo outStorageVo, final Map<String, Object> map)
			throws ServiceException {

		if(outStorageVo==null
				||CollectionUtils.sizeIsEmpty(map)){
			throw new ServiceException("更新出库码参数有误");
		}
		final String enterpriseCode = outStorageVo.getEnterpriseCode();
		final short channelType = outStorageVo.getChannelType();
		@SuppressWarnings("unchecked")
		final List<MultistageLevelQRCode> outPackLevelCodeList = (List<MultistageLevelQRCode>) map.get("outPackLevelCodeList");
		@SuppressWarnings("unchecked")
		final List<FirstLevelQRCode> outSingleLevelCodeList = (List<FirstLevelQRCode>) map.get("outSingleLevelCodeList");
		try{
			// 1、改为出库状态
			final int outStorageStatus = QRCodeUtil.getOutStorageCodeStatus(channelType);
			final Set<String> packUpLevelSet = new HashSet<String>(); // 需要解除关系的包装上级码
			final List<String> packContentList = new ArrayList<String>(); // 需要更新的包装码
			LOGGER.info("更新码的状态为出库状态开始...");
			if(CollectionUtils.isNotEmpty(outPackLevelCodeList)) {
				for(final MultistageLevelQRCode item:outPackLevelCodeList) {
//					item.setStatus(outStorageStatus);
//					multistageLevelQRCodeDao.updateOne(item);
					packContentList.add(item.getPackContent());
					if(StringUtils.isNotBlank(item.getParentCode())) {
						packUpLevelSet.add(item.getParentCode()); // 要解除下级关系的上级码集合
					}
				}
				final MultistageLevelQRCode updateMulti = new MultistageLevelQRCode();
				updateMulti.setEnterpriseCode(enterpriseCode);
				updateMulti.setStatus(outStorageStatus); // 更新为相应的入库状态
				multistageLevelQRCodeDao.batchUpdateByPackContentList(updateMulti, packContentList);
				LOGGER.info("需要更新为出库状态的包装码集合为:{},更改方式为:状态改为:{}", JSONObject.toJSONString(packContentList), outStorageStatus);
			}
			if(CollectionUtils.isNotEmpty(outSingleLevelCodeList)){
				final List<String> qrCodeList = new ArrayList<String>(); // 需要更新的单品码
				for(final FirstLevelQRCode item:outSingleLevelCodeList) {
//					item.setStatus(outStorageStatus);
//					firstLevelQRCodeService.update(item);
					qrCodeList.add(item.getQrCode());
				}
				final FirstLevelQRCode updateFirstCode = new FirstLevelQRCode();
				updateFirstCode.setEnterpriseCode(enterpriseCode);
				updateFirstCode.setStatus(outStorageStatus); // 更新为相应的入库状态
				firstLevelQRCodeService.batchUpdateByQrCodeList(updateFirstCode, qrCodeList);
				LOGGER.info("需要更新为出库状态的单品码集合为:{},更改方式为:状态改为:{}", JSONObject.toJSONString(qrCodeList), outStorageStatus);
			}
			// 2、解除虚拟码与包装码的关系
			LOGGER.info("解除虚拟码与包装码的关系开始...");
			if(!CollectionUtils.isEmpty(packContentList)) {
				final MultistageLevelQRCode updateMulti = new MultistageLevelQRCode();
				updateMulti.setEnterpriseCode(enterpriseCode);
				updateMulti.setParentCode(""); // 解除上级码
				LOGGER.info("需解除上级包装码的包装码列表为:{},更改方式为:parentCode改为空字符串", JSONObject.toJSONString(packContentList));
				multistageLevelQRCodeDao.batchUpdateByPackContentList(updateMulti, packContentList);
			}
			if(!CollectionUtils.isEmpty(packUpLevelSet)) {
				final MultistageLevelQRCode updateMulti = new MultistageLevelQRCode();
				updateMulti.setEnterpriseCode(enterpriseCode);
				updateMulti.setChildNum(0);
				updateMulti.setChilds("");
				final List<String> packUpLevelList = new ArrayList<String>();
				CollectionUtils.addAll(packUpLevelList, packUpLevelSet.toArray());
				LOGGER.info("需解除下级包装码的包装上级码列表为:{},更改方式为:childNum改为0,childs改为空字符串", JSONObject.toJSONString(packUpLevelList));
				multistageLevelQRCodeDao.batchUpdateByPackContentList(updateMulti, packUpLevelList);
			}
			LOGGER.info("解除虚拟码与包装码的关系结束...");
		}catch(Exception e){
			throw new ServiceException(e);
		}
		
	}

	/**(non-Javadoc)
	 *@Title: updateInStorageCode
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#updateInStorageCode(com.sigmatrix.sc.handheld.inter.web.vo.InStorageVo, java.util.Map)
	 *@author youjun
	 *@date 2017年8月22日 下午3:07:16
	 */
	@Override
	public void updateInStorageCode(InStorageVo inStorageVo, Map<String, Object> map) throws ServiceException {
		if(inStorageVo==null
				||CollectionUtils.sizeIsEmpty(map)){
			throw new ServiceException("更新入库码参数有误");
		}
		@SuppressWarnings("unchecked")
		final List<MultistageLevelQRCode> inPackLevelCodeList = (List<MultistageLevelQRCode>) map.get("inPackLevelCodeList");
		@SuppressWarnings("unchecked")
		final List<FirstLevelQRCode> inSingleLevelCodeList = (List<FirstLevelQRCode>) map.get("inSingleLevelCodeList");
		final String enterpriseCode = inStorageVo.getEnterpriseCode();
		try{
			// 1、改为入库状态 
			LOGGER.info("更新入库码状态开始...");
			if(CollectionUtils.isNotEmpty(inPackLevelCodeList)) {
				final List<String> packContentList = new ArrayList<String>(); // 需要更新的多级码
				for(final MultistageLevelQRCode item:inPackLevelCodeList) {
//					item.setStatus(MultistageLevelQRCodeStatusEnum.IN_STORAGE.getId());
//					multistageLevelQRCodeDao.updateOne(item);
					packContentList.add(item.getPackContent());
				}
				final MultistageLevelQRCode updateMulti = new MultistageLevelQRCode();
				updateMulti.setEnterpriseCode(enterpriseCode);
				updateMulti.setStatus(MultistageLevelQRCodeStatusEnum.IN_STORAGE.getId()); // 更新为入库状态
				LOGGER.info("需要更新为入库状态的包装码集合为:{},状态更改为:{}", JSONObject.toJSONString(packContentList), MultistageLevelQRCodeStatusEnum.IN_STORAGE.getId());
				multistageLevelQRCodeDao.batchUpdateByPackContentList(updateMulti, packContentList);
			}
			if(CollectionUtils.isNotEmpty(inSingleLevelCodeList)){
				final List<String> qrCodeList = new ArrayList<String>(); // 需要更新的单品码
				for(final FirstLevelQRCode item:inSingleLevelCodeList) {
//					item.setStatus(MultistageLevelQRCodeStatusEnum.IN_STORAGE.getId());
//					firstLevelQRCodeService.update(item);
					qrCodeList.add(item.getQrCode());
				}
				final FirstLevelQRCode updateFirstCode = new FirstLevelQRCode();
				updateFirstCode.setEnterpriseCode(enterpriseCode);
				updateFirstCode.setStatus(MultistageLevelQRCodeStatusEnum.IN_STORAGE.getId()); // 更新为入库状态
				firstLevelQRCodeService.batchUpdateByQrCodeList(updateFirstCode, qrCodeList);
				LOGGER.info("需要更新为入库状态的单品码集合为:{},状态更改为:{}", JSONObject.toJSONString(qrCodeList), MultistageLevelQRCodeStatusEnum.IN_STORAGE.getId());
			}
			// 2、有组垛操作的话要建立虚拟码与包装码的关系
			LOGGER.info("需组垛操作的话,建立虚拟码与包装码的关系开始...");
			@SuppressWarnings("unchecked")
			final Map<ProductData, List<OperateCodeVo>> groupStackOperateCodeVoMap = (Map<ProductData, List<OperateCodeVo>>) map.get("groupStackOperateCodeVoMap");
			if(!CollectionUtils.sizeIsEmpty(groupStackOperateCodeVoMap)) {
				MultistageLevelQRCode referenceMultisQRCode = null;
				for(final ProductData product:groupStackOperateCodeVoMap.keySet()) {
					final List<OperateCodeVo> list = groupStackOperateCodeVoMap.get(product);
					if(!CollectionUtils.isEmpty(list)) {
						referenceMultisQRCode = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, list.get(0).getCode());
						final Map<Integer, List<String>> codeMapByStackTage = new HashMap<Integer, List<String>>();
						List<String> codeList = null;
						for(final OperateCodeVo vo:list) {
							codeList = new ArrayList<String>();
							if(codeMapByStackTage.containsKey(vo.getStackTag())) {
								codeList = codeMapByStackTage.get(vo.getStackTag());
							}
							codeList.add(vo.getCode());
							codeMapByStackTage.put(vo.getStackTag(), codeList);
						}
						for(final Integer stackTage:codeMapByStackTage.keySet()) {
							// 生成一个顶级码
							final String bigCode = this.generatedMultistageQRCode(enterpriseCode, referenceMultisQRCode, 
									"", product.getBigLevel(), Cons.CODE_CATEGORY_PREFIX_STACK);
							this.packGroupSplitStack(enterpriseCode, bigCode, codeMapByStackTage.get(stackTage), 
									PackScanOperTypeEnum.ADD_NEW_STACK.getId(), product);
						}
					}
				}
				
			}
			LOGGER.info("需组垛操作的话,建立虚拟码与包装码的关系结束...");
		}catch(Exception e){
			throw new ServiceException(e);
		}
	}
	
	/**
	 *@Title: validatePackLevelCode
	 *@Description: 判断<b>"包装级别码"</b>是否为null、是否出库、是否满包装,返回错误包装数
	 *@return int
	 *@author youjun
	 *@date 2017年8月12日 上午1:27:50
	 *@param qRCodeErrorList
	 *@param item
	 *@param operateCode 手持<b>直接</b>上传的是包装码就传入,否则传入""
	 *@param product
	 *@param isSelf 是否为多级码本身
	 *@param type 1为出库,2为入库
	 *@return
	 * @throws ServiceException 
	 */
	@SuppressWarnings("unused")
	@Override
	public int validatePackLevelCode(final List<QRCodeError> qRCodeErrorList, final MultistageLevelQRCode item,
			final String operateCode, final ProductData product, final boolean isSelf, final int type , Integer warehouseId, OutStorageVo outStorageVo) throws ServiceException {

		if(qRCodeErrorList==null
				||product==null) {
			throw new ServiceException("参数有误");
		}
		QRCodeError qRCodeError = null;
		final Integer packLevel = product.getProductUnit().intValue();
		final Integer productId = product.getProductId();
		final Map<Integer, String> packStandardMap = product.getPackStandardMap();
		final String packUnit = product.getPackUnit();
		final Integer mulPackLevel = item.getPackLevel();//多级码的包装级别
		String packCode = item.getPackContent();
		if(item==null) {
			qRCodeError = new QRCodeError(operateCode, packLevel, productId, new StringBuilder(packUnit).append("码不存在").toString());
			qRCodeErrorList.add(qRCodeError);
			return 1;
		}
		StringBuilder errorMsg = null;
		// 暂时注释判断逻辑
		/*if(type==1&&alreadyOutStorageStatusList.contains(item.getStatus())) {
			packCode = StringUtils.isBlank(operateCode)?item.getPackContent():operateCode;
			qRCodeError = new QRCodeError(packCode, packLevel, productId, "码已出库");
			qRCodeErrorList.add(qRCodeError);
			return 1;
		}
		if(type==2&&alreadyInStorageStatusList.contains(item.getStatus())) {
			packCode = StringUtils.isBlank(operateCode)?item.getPackContent():operateCode;
			qRCodeError = new QRCodeError(packCode, packLevel, productId, "码已入库");
			qRCodeErrorList.add(qRCodeError);
			return 1;
		}*/
		//箱码放行，如盒码绑定了上级码不放行
		if (mulPackLevel<packLevel) {
			if(StringUtils.isNotBlank(item.getParentCode()) && isSelf) {
				errorMsg = new StringBuilder("当前").append(packStandardMap.get(item.getPackLevel())).append("码存在");
				errorMsg.append(packStandardMap.get(item.getPackLevel()));
				errorMsg.append(packStandardMap.get(item.getPackLevel()+1)).append("关联,不能进行操作");
//				return new Response(Cons.RESPONSE_CODE_DATA_EXCEPTION, errorMsg.toString());
				qRCodeError = new QRCodeError(packCode, 1, productId, errorMsg.toString());
				qRCodeErrorList.add(qRCodeError);
				return 1;
			}
		}
		
		if(isSelf) { // 单独出、入包装单位才判断是否满箱，出入库垛下的箱不做任何判断
			packCode = StringUtils.isBlank(operateCode)?item.getPackContent():operateCode;
			// 判断是否满包装
			final int packSubNum = productService.getCodeHaveSpecifiedLevelCount(product, packLevel, packLevel-1); // 包装规格规定的下级数量
			final int childNum = item.getChildNum()==null?0:item.getChildNum(); // 实际下级数量
			if(childNum!=packSubNum) {
				errorMsg = new StringBuilder(packUnit);
				errorMsg.append("码中包装的").append(packStandardMap.get(packLevel-1)).append("不符合包装规格");
				qRCodeError = new QRCodeError(packCode, packLevel, productId, errorMsg.toString());
				qRCodeErrorList.add(qRCodeError);
				return 1;
			}
		}
		//校验码是否已出库以及是否在库
		if (Utils.isNotEmpty(warehouseId)) {
			 //查询码是否是所属仓库(销售出库验证)
			Integer numWarehouse = warehouseStockDetailsService.countByConditionOut(item.getEnterpriseCode(), warehouseId, productId, packCode,Cons.WH_STOCK_STATUS_ALREADY_IN_STORAGE,true);
			if (Utils.isEmptyZero(numWarehouse)) {
				qRCodeError = new QRCodeError(packCode, packLevel, productId, "该码不存在"+outStorageVo.getWarehouseName()+"仓库中或已出库");
				qRCodeErrorList.add(qRCodeError);
				return 1;
			}
			
			//此场景为调拨出库放行，1号仓库调拨出库到2号仓库 一箱A ， 2号仓库做收货入库，入库箱A，可以成功入库并且2号仓库库存发生改变多了箱A。   然后 2号仓库调拨出库回去到1号仓库箱A。出库成功后。2号仓库箱A，出去了。  1号仓库做收货入库
			int  numCount = warehouseStockDetailsService.countByConditionOut(item.getEnterpriseCode(), warehouseId, productId, packCode, Cons.WH_STOCK_STATUS_ALREADY_IN_STORAGE, false);
			if (numCount > 1) {
				return 0;
			}
			
			//查询码是否已出库(销售出库验证)
			 Integer num = warehouseStockDetailsService.countByConditionOut(item.getEnterpriseCode(), warehouseId, productId, packCode,Cons.WH_STOCK_DETAILS_STATUS_OUT_STORAGE,true);
			 if(num>0){
					qRCodeError = new QRCodeError(packCode, packLevel, productId, "码已出库");
					qRCodeErrorList.add(qRCodeError);
					return 1;
			 }
			
		
		}
		
		return 0;
	}
	
	/**
	 *@Title: validateCodeIsFullPack
	 *@Description: 验证码是否满包装,满包装将返回null,否则返回QRCodeError对象
	 *@return QRCodeError
	 *@author youjun
	 *@date 2017年8月25日 下午5:03:37
	 *@param item
	 *@param product
	 *@return
	 *@throws ServiceException
	 */
	@Override
	public QRCodeError validateCodeIsFullPack(final MultistageLevelQRCode item, final ProductData product) throws ServiceException {
		
		if(item==null
				||product==null) {
			throw new ServiceException("验证码是否满包装参数有误");
		}
		// 判断是否满包装
		final int packLevel = product.getProductUnit().intValue();
		final int packSubNum = productService.getCodeHaveSpecifiedLevelCount(product, packLevel, packLevel-1); // 包装规格规定的下级数量
		final int childNum = item.getChildNum()==null?0:item.getChildNum(); // 实际下级数量
		QRCodeError qRCodeError = null;
		if(childNum!=packSubNum) {
			final Map<Integer, String> packStandardMap = product.getPackStandardMap();
			final String packUnit = product.getPackUnit();
			final StringBuilder errorMsg = new StringBuilder(packUnit);
			errorMsg.append("码中包装的").append(packStandardMap.get(packLevel-1)).append("不符合包装规格");
			qRCodeError = new QRCodeError(item.getPackContent(), packLevel, product.getProductId(), errorMsg.toString());
		}
		return qRCodeError;
	}


	/**(non-Javadoc)
	 *@Title: getSpecifiedLevelCode
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#getSpecifiedLevelCode(java.lang.String, java.lang.String, int, boolean, int)
	 *@author youjun
	 *@date 2017年8月17日 上午2:11:32
	 */
	@Override
	public MultistageLevelQRCode getSpecifiedUpLevelCode(final String enterpriseCode, final String packContent, 
			final Integer codeLevel, final boolean isNeedConversion, int specifiedLevel) throws ServiceException {

		if(StringUtils.isBlank(enterpriseCode)
				||StringUtils.isBlank(packContent)
				||specifiedLevel<1) {
			throw new ServiceException("获得指定码级别的码信息参数有误");
		}
		try{
			// 查询当前码
			final String code = QRCodeUtil.conversionQRCode(packContent, isNeedConversion);
			final MultistageLevelQRCode currentMultis = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCodeAndLevel(enterpriseCode, code, codeLevel);
			if(currentMultis==null) {
				return null;
			}
			MultistageLevelQRCode specifiedUpLevelCode = currentMultis;
			final int currentCodeLevel = currentMultis.getPackLevel();
			if(currentCodeLevel > specifiedLevel) {
				throw new ServiceException("只能查询指定的上级码，不能查询下级码");
			}
			if(currentCodeLevel==specifiedLevel) {
				return currentMultis;
			}else{ // 找指定的上级码
				String parentCode = currentMultis.getParentCode();
				if(StringUtils.isBlank(parentCode)) {
					return null;
				}
				for(int i=currentCodeLevel+1;i<=specifiedLevel;i++) {
					parentCode = specifiedUpLevelCode==null?"":specifiedUpLevelCode.getParentCode();
					if(StringUtils.isBlank(parentCode)
							&& i!=specifiedLevel) {
						return null;
					}
					specifiedUpLevelCode = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, parentCode);
				}
			}
			return specifiedUpLevelCode;
		}catch(Exception e){
			LOGGER.error("getSpecifiedLevelCode fail", e);
			throw new ServiceException(e);
		}
	}

	/**(non-Javadoc)
	 *@Title: packGroupSplitBox
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#packGroupSplitBox(java.lang.String, java.lang.String, java.util.List, int)
	 *@author youjun
	 *@date 2017年8月18日 下午8:41:22
	 */
	@Override
	public void packGroupSplitBox(final String enterpriseCode, final String packCode, final List<String> operateCodeList, 
			final int operationType)
			throws ServiceException {

		if(StringUtils.isBlank(enterpriseCode)
				||StringUtils.isBlank(packCode)
				||CollectionUtils.isEmpty(operateCodeList)
				||(operationType!=PackScanOperTypeEnum.GROUP_OR_FILL_BOX.getId()&&
						operationType!=PackScanOperTypeEnum.SPLIT_BOX.getId())) {
			throw new ServiceException("组/拆箱操作参数错误");
		}
		try{
			final MultistageLevelQRCode packMultis = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, packCode);
			if(packMultis==null) {
				throw new ServiceException("包装码不存在");
			}
			final int childNum = packMultis.getChildNum()!=null?packMultis.getChildNum():0; // 子码数量
			String childs = packMultis.getChilds(); // 子码
			String tempChilds = "";
			if(StringUtils.isNotBlank(childs)) {
				childs = childs.replace(" ", ""); // 去除空格,如:xx1, xx2, xx3
				// 行如:,xx1,xx2,xx3,
				tempChilds = new StringBuilder(",").append(childs).append(",").toString();
			}
			int updateChildNum = 0;
			String updateChilds = "";
			if(operationType==PackScanOperTypeEnum.GROUP_OR_FILL_BOX.getId()) { // 组箱
				updateChildNum = childNum + operateCodeList.size();
				updateChilds = new StringBuilder(childs)
						.append((childNum==0?"":",")).append(operateCodeList.toString().replace(" ","").replace("[", "")
								.replace("]", "")).toString();
			}else{ // 拆箱
				if(StringUtils.isBlank(childs)) {
					throw new ServiceException("没有子码不能拆");
				}
				for(final String operateCode:operateCodeList) {
					final StringBuilder operateCodeSb = new StringBuilder(",").append(operateCode).append(",");
					if(tempChilds.contains(operateCodeSb)) {
						tempChilds = tempChilds.replace(operateCodeSb, ",");
					}
				}
				// 去除头尾","
				if(tempChilds.startsWith(",")) {
					tempChilds = tempChilds.substring(1);
				}
				if(tempChilds.endsWith(",")) {
					tempChilds = tempChilds.substring(0, tempChilds.length()-1);
				}
				updateChilds = tempChilds;
				updateChildNum = childNum - operateCodeList.size();
			}
			packMultis.setChildNum(updateChildNum);
			packMultis.setChilds(updateChilds);
			multistageLevelQRCodeDao.updateOne(packMultis);
			// 拆除(拆箱操作)或填充(组、补箱操作)下级码的上级码字段
			final String parentCode = operationType==PackScanOperTypeEnum.GROUP_OR_FILL_BOX.getId()?packCode:"";
			if(packMultis.getPackLevel()>2) { // 说明下级码也是多级码
				multistageLevelQRCodeDao.batchSplitOrFillParentCode(enterpriseCode, operateCodeList, parentCode);
			}else{ // 更新单品码
				firstLevelQRCodeService.batchSplitOrFillParentCode(enterpriseCode, operateCodeList, parentCode);
			}
		}catch(DaoException e){
			throw new ServiceException(e);
		}
		
	}

	/**(non-Javadoc)
	 *@Title: packGroupSplitStack
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#packGroupSplitStack(java.lang.String, java.lang.String, java.util.List, int, com.sigmatrix.sc.handheld.inter.dto.ProductData)
	 *@author youjun
	 *@date 2017年8月20日 下午5:24:47
	 */
	@Override
	public void packGroupSplitStack(final String enterpriseCode, final String targetCode, final List<String> operateCodeList,
			final int operationType, final ProductData product) throws ServiceException {

		/*
		 * 1、多级关系:箱层垛
		 * 拆垛操作:只拆箱和层的关系
		 * 补垛:只补箱层关系
		 * 组新垛操作(提供了垛码<目标码>):
		 * 2、上下级关系:箱垛
		 * 拆垛操作:拆箱垛关系
		 * 补垛操作:补箱垛关系
		 * 
		 */
		if(StringUtils.isBlank(enterpriseCode)
				||StringUtils.isBlank(targetCode)
				||CollectionUtils.isEmpty(operateCodeList)
				||product==null) {
			throw new ServiceException("拆/补/组新箱操作参数错误");
		}
		final int packLevel = product.getProductUnit().intValue(); // 包装级别
		final int bigLevel = product.getBigLevel(); // 最大级别
		// 目前只支持包装单位上面有两级，如包装单位的级别为3,当前的最大包装级别为5
		if(packLevel+2<bigLevel) {
			throw new ServiceException("目前只支持最大单位比包装单位级别做多大2级");
		}
		try{
			final MultistageLevelQRCode targetCodeMultisQRCode = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, targetCode);
			// 补垛、拆垛,都是更新当前包装码的上级码字段(补垛:填充为目标码,拆垛:清空上级码),将上级码的childNum和childs字段进行更新
			final Map<String, List<String>> duoMap = new HashMap<String, List<String>>();
			String parentCode = targetCode; // 默认为补垛
			if(operationType==PackScanOperTypeEnum.SPLIT_STACK.getId()) { // 拆垛,设为""
				parentCode = "";
			}
			int i = 1;
			// 包装上级码拥有包装码的数量
			final int subNum = productService.getCountHaveSpecifiedLevelCount(product, packLevel+1, packLevel);
			for(final String operateCode:operateCodeList) {
				if(operationType==PackScanOperTypeEnum.ADD_NEW_STACK.getId()
						&&(i%subNum==1||subNum==1)) {
					if(packLevel+1!=bigLevel) { // 包装单位和最大单位不止差一级
						parentCode = generatedMultistageQRCode(enterpriseCode, targetCodeMultisQRCode, targetCode, packLevel+1, Cons.CODE_CATEGORY_PREFIX_LAYER); // 层码
						List<String> childs = new ArrayList<String>();
						if(duoMap.containsKey(targetCode)) {
							childs = duoMap.get(targetCode);
						}
						childs.add(parentCode);
						duoMap.put(targetCode, childs);
					}
				}
				// 更新当前包装码的上级码字段(补垛:填充为目标码,拆垛:清空上级码)
				final MultistageLevelQRCode packMultisQRCode = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, operateCode);
				final MultistageLevelQRCode packMultisQRCodeCondition = new MultistageLevelQRCode();
				packMultisQRCodeCondition.setPackContent(operateCode);
				packMultisQRCodeCondition.setParentCode(parentCode);
				multistageLevelQRCodeDao.updateOne(packMultisQRCodeCondition);
				// 将上级码的childNum和childs字段进行更新
				final String upLevelCode = operationType==PackScanOperTypeEnum.SPLIT_STACK.getId()?packMultisQRCode.getParentCode():parentCode;
				final MultistageLevelQRCode parentCodeMultis = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, upLevelCode);
				int updateChildNum = parentCodeMultis.getChildNum()+1; // 默认为补垛,组新垛也如此
				String updateChilds = StringUtils.isBlank(parentCodeMultis.getChilds())?operateCode:(parentCodeMultis.getChilds()+","+operateCode); // 默认为补垛,组新垛也如此
				if(operationType==PackScanOperTypeEnum.SPLIT_STACK.getId()) { // 拆垛
					updateChildNum = parentCodeMultis.getChildNum() - 1;
					final List<String> parentCodeHaveChilds = new ArrayList<String>();
					CollectionUtils.addAll(parentCodeHaveChilds, parentCodeMultis.getChilds().split(","));
					parentCodeHaveChilds.remove(operateCode);
					updateChilds = parentCodeHaveChilds.toString().replace(" ", "").replace("[", "").replace("]", "");
				}
				parentCodeMultis.setChildNum(updateChildNum);
				parentCodeMultis.setChilds(updateChilds);
				multistageLevelQRCodeDao.updateOne(parentCodeMultis);
				i++; // 计数+1
			}
			// 新增码的操作中已经更新了上级码的子码内容和子码数量,以下可考虑不要
			if(operationType==PackScanOperTypeEnum.ADD_NEW_STACK.getId()
					&&packLevel+1!=bigLevel) { // 组新垛,且包装单位和最大单位不止差一级,更新最大级别码
				final List<String> duoChilds = duoMap.get(targetCode);
				final MultistageLevelQRCode duoCodeMultis = new MultistageLevelQRCode();
				duoCodeMultis.setEnterpriseCode(enterpriseCode);
				duoCodeMultis.setPackContent(targetCode);
				duoCodeMultis.setChildNum(duoChilds.size());
				duoCodeMultis.setChilds(duoChilds.toString().replace(" ", "").replace("[", "").replace("]", ""));
				multistageLevelQRCodeDao.updateOne(duoCodeMultis);
			}
			
		}catch(Exception e){
			throw new ServiceException(e);
		}
	}

	/**
	 *@Title: generatedParentCode
	 *@Description: 生成多级码
	 *@return String
	 *@author youjun
	 *@date 2017年8月20日 下午8:20:25
	 *@param enterpriseCode
	 *@param referenceMultisQRCode 参考码,必须为库中的码,取其中的共有信息
	 *@param parentCode 上级码
	 *@param codeLevel 生成的码的级别
	 *@return
	 */
	@Override
	public String generatedMultistageQRCode(String enterpriseCode, MultistageLevelQRCode referenceMultisQRCode, 
			String parentCode, int codeLevel, final String codeCategoryPrefix) throws ServiceException {

		final String layerCode = QRCodeUtil.generatedCode(StringUtils.isBlank(codeCategoryPrefix)?Cons.CODE_CATEGORY_PREFIX_LAYER:codeCategoryPrefix); // 默认层码
		final MultistageLevelQRCode multistageQRCode = new MultistageLevelQRCode();
		try{
			// 判断parentCode是否存在
			MultistageLevelQRCode parentMultis = null;
			if(StringUtils.isNotBlank(parentCode)) { // 上级码非空,将上级码关联该码
				parentMultis = multistageLevelQRCodeDao.findMultistageLevelQRCodeByQRCode(enterpriseCode, parentCode);
				if(parentMultis==null) {
					throw new ServiceException("上级码不存在,无法生成");
				}
			}
			multistageQRCode.setPackContent(layerCode);
			multistageQRCode.setChildNum(0);
			multistageQRCode.setChilds("");
			multistageQRCode.setCreateTime(new Date());
			multistageQRCode.setEnterpriseCode(enterpriseCode);
			multistageQRCode.setPackLevel(codeLevel);
			multistageQRCode.setParentCode(parentCode);
			multistageQRCode.setProductId(referenceMultisQRCode.getProductId());
			multistageQRCode.setBatchCode(referenceMultisQRCode.getBatchCode());
			multistageQRCode.setDealersId(referenceMultisQRCode.getDealersId());
			multistageQRCode.setWarehouseId(referenceMultisQRCode.getWarehouseId());
		
			//multistageLevelQRCodeDao.save(multistageQRCode);
			mongoTemplate.save(multistageQRCode);
			if(StringUtils.isNotBlank(parentCode)) { // 上级码非空,将上级码关联该码
				parentMultis.setChildNum(parentMultis.getChildNum()==null?1:parentMultis.getChildNum()+1);
				final String updateChilds = StringUtils.isBlank(parentMultis.getChilds())?layerCode:(parentMultis.getChilds()+","+layerCode);
				parentMultis.setChilds(updateChilds);
				multistageLevelQRCodeDao.updateOne(parentMultis);
			}
		}catch(DaoException e){
			throw new ServiceException(e);
		}
		return layerCode;
	}

	/**(non-Javadoc)
	 *@Title: findMultistageLevelQRCodeByCondition
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#findMultistageLevelQRCodeByCondition(com.sigmatrix.sc.handheld.inter.entity.MultistageLevelQRCode)
	 *@author youjun
	 *@date 2017年8月21日 下午1:35:55
	 */
	@Override
	public List<MultistageLevelQRCode> findMultistageLevelQRCodeByCondition(
			final MultistageLevelQRCode multistageLevelQRCodeCondition) throws ServiceException {

		try {
			return multistageLevelQRCodeDao.findMultistageLevelQRCodeByCondition(multistageLevelQRCodeCondition);
		}catch(Exception e) {
			throw new ServiceException(e);
		}
	}
	
	/**
	 * (non-Javadoc)
	 *@Title: updateOne
	 *@Description: 
	 *@see com.sigmatrix.sc.handheld.inter.service.MultistageLevelQRCodeService#updateOne(com.sigmatrix.sc.handheld.inter.entity.MultistageLevelQRCode)
	 *@author youjun
	 *@date 2017年8月22日 上午11:29:08
	 */
	@Override
	public void updateOne(final MultistageLevelQRCode multistageLevelQRCode) throws ServiceException {
		try{
			multistageLevelQRCodeDao.updateOne(multistageLevelQRCode);
		}catch(Exception e){
			throw new ServiceException(e);
		}
	}

//	@Override
//	public List<MultistageLevelQRCode> select(MultistageLevelQRCode t, Map<String, String> order, String eseCode) {
//		// TODO Auto-generated method stub
//		return null;
//	}


}
